package com.yys.zproject.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.yys.zproject.dao.UserDao;
import com.yys.zproject.dao.impl.UserDaoimpl;
import com.yys.zproject.entity.UserEntity;
import com.yys.zproject.service.UserService;

import java.sql.SQLException;


public class UserServiceimpl implements UserService {
    @Override
    public void register(UserEntity user) throws SQLException {
        //TODO: 实现注册逻辑
        System.out.println("UserService正在处理注册"+user);
        UserDao userDao = new UserDaoimpl();

        String password = user.getPassword();

        String md5 = SecureUtil.md5(password);
        user.setPassword(md5);
        userDao.save(user);

    }
    @Override
    public UserEntity login(String username, String password)
    {
        UserDao userDao = new UserDaoimpl();
        String md5=SecureUtil.md5(password);
        UserEntity userEntity = userDao.getUserByUsernameAndPassword(username, md5);
        return userEntity;
    }


}
